import { observable, action, computed, toJS } from 'mobx';
import { WeaTools } from "ecCom"
import { message, Modal } from 'antd';
const confirm = Modal.confirm;
import { WeaLocaleProvider } from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import {TaskGroupStore} from "./taskGroupStore" 
import * as Apis from '../../apis/prjPortal';
const { ls } = WeaTools;
import {WeaTableNew,WeaForm} from 'comsMobx'
const {TableStore} = WeaTableNew;
import { ListStore } from '../listStore';
import {ShareStore } from '../shareStore'
import {ExchangeStore } from "../exchangeStore"
import {TaskInfoStore} from '../task/taskInfoStore'
class TaskPortalStore extends ListStore {

    @observable title = getLabel('518195','任务门户');

    @observable taskGroupStore = new TaskGroupStore();

    @observable taskGroupStore1 = new TaskGroupStore();

    @observable groups = [];

    @observable prjtypes = [];

    @observable loading  = false;

    @observable topTabCount =[];
	@observable baseParams={};
	searchParams =  {
		tabkey: "all",
	}
	@observable rightMenu =[];
	conditiontype = {conditiontype:"execute"};
	
	@observable shareStore = new ShareStore();
	@observable exchangeStore = new ExchangeStore();
	@observable taskInfoStore = new TaskInfoStore();

    @observable isreloadWorkPlan = false;
    @observable prjSearchDatas = [];

    @observable counts = {};

    @observable searchValue = '';

    // @observable tableStore = new TableStore(); 

    @action
    initDatas_del = (params={}) =>{
        this.pageIndex =1
        const newParams = {groupid:this.prjGroupStore.id,...params,pageIndex : this.pageIndex,pageSize:this.pageSize};
        this.prjDatas = [];
        Apis.getProjectDatas(newParams).then(data=>{
            this.prjDatas = data.prjDatas;
            this.prjSearchDatas = data.prjSearchDatas;
            this.groups = data.groups;
            this.prjtypes = data.prjtypes;
            this.tableStore.getDatas(data.sessionkey, 1);
            this.hasNext = data.hasNext;
            // this.pageSize = data.pageSize;
            // this.pageIndex = data.pageIndex;
            ls.set("prj_portal_datas", this.prjSearchDatas);
        })
    }

    @action
	setLoaded=()=>{
		this.isreloadWorkPlan= true;
    }
    
    
	onShowColumn=()=>{  //显示定制列
		this.tableStore.setColSetVisible(true);
		this.tableStore.tableColSet(true)
	}

    //项目分组删除
	deleteTaskGroupInfo=(params={})=>{
        Modal.confirm({
            title: getLabel('130629','删除分组'),
            content: getLabel('511907','确认要删除该分组？'),
            onOk: () => {
                let newParams = {...params,operation:'delete'};
				Apis.doTaskGroupOperation(newParams).then(data=>{
                    if(data.success){
                        message.success(getLabel(83472, "删除成功！"));
                        this.doSearch();
                    }else{
                        message.error(getLabel('507580','出现错误！对不起，您暂时没有权限！！'));
                    }
				})
            }
        });
    }
    

    @action
    doSearch=(params={})=>{
		this.loading = true;
		 //获取表单的参数值
		 const searchParamsAd = this.form.getFormParams();
		 const newParams = { ...this.baseParams, ...this.searchParams, ...searchParamsAd, ...params, searchValue:this.searchValue };
        Apis.getTaskExecuteList(newParams).then(data=>{
            this.tableStore = new TableStore();
            this.tableStore.getDatas(data.sessionkey,  params.current || 1);
            this.groups = data.groups;
			this.searchParams = { ...this.searchParams, ...params };
			this.topTabCount = data.tabnum;
			this.dataKey = data.sessionkey;
            this.rightMenu = data.rightMenus;
            this.counts = data.counts;
            this.loading = false;
        })
    }

    @action
	appendBaseParams=(params)=> {
        this.baseParams = {...this.baseParams,...params};
    }

    @action
    initDatas=(params = {})=> {
		let newParams = {...this.conditiontype,...params};
		this.topTabCount = this.topTabCount;    
		Apis.getTaskCondition(newParams).then(data=>{
			this.condition = data.condition;
			//根据高级搜索条件初始化form
			this.form && !this.form.isFormInit && this.form.initFormFields(data.condition);
		});
	}
    
    clearStatus=()=>{
        this.searchValue = '';
        this.form.reset();
    }

    @action
    quickSearch = () =>{
        const params = {operation:'quickSearch',searchValue:this.searchValue};
        Apis.doTaskGroupOperation(params).then(data=>{
            if(data.success){
                this.groups = data.groups;
            }else{
                message.error(data.msg);
            }
        })
    }

    @action
    setSearchValue = (v) =>{
        this.searchValue = v;
    }

}

const taskPortalStore = new TaskPortalStore();
export default taskPortalStore;